home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 220 / 220.xpi / chrome / flashgot.jar / content / flashgot / DAP.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2010-01-24  |  1.9 KB  |  89 lines

  1. #include "FlashGot.h"
  2.  
  3. #import "progid:InternetExplorer.Application.1"
  4. #import "progid:ScriptBridge.ScriptBridge.1" 
  5. using namespace SHDocVw;
  6. using namespace MSHTML;
  7.  
  8.  
  9.  
  10. void DMSDownloadAcceleratorPlus::dispatch(const DownloadInfo *downloadInfo)
  11. {
  12.     HELPER(helper);
  13.     switch(downloadInfo->opType) 
  14.     {
  15.         case OP_ONE:
  16.         {
  17.             VARIANT v[4];
  18.             LinkInfo l=downloadInfo->links[0];
  19.             v[0].vt=v[1].vt=v[2].vt=v[3].vt=v[3].vt=VT_BSTR;
  20.             v[3].bstrVal= l.url; // URL
  21.             v[2].bstrVal= downloadInfo->referer ; // Referer
  22.             v[1].bstrVal= l.cookie ; // cookie
  23.             v[0].bstrVal= l.comment ; // info
  24.             helper.invoke("MenuUrl2",v,4);
  25.             break;
  26.         }
  27.         
  28.         case OP_SEL: case OP_ALL:
  29.         {
  30.             IWebBrowser2Ptr ie(__uuidof(InternetExplorer));    
  31.             InternetSetCookie(downloadInfo->referer,NULL,downloadInfo->extras[0]);
  32.             
  33.             
  34.             ie->PutSilent(VARIANT_TRUE);
  35.             ie->PutOffline(VARIANT_TRUE);
  36.             
  37.             VARIANT v1,v2;
  38.             v1.vt=v2.vt=VT_BSTR;
  39.             v1.bstrVal=downloadInfo->referer;
  40.             v2.bstrVal="Referer: "+downloadInfo->extras[1];
  41.             
  42.             
  43.             ie->Navigate2(&v1,&vtMissing,&vtMissing,&vtMissing,&v2);
  44.             long timeout=DMS_POLL_TIMEOUT;
  45.             for(int j = 2; j--> 0;)
  46.             {
  47.                 while(!ie->ReadyState)
  48.                 { 
  49.                     if( (timeout -= DMS_POLL_DELAY) <0) 
  50.                     {
  51.                         fail("DAP Timeout", 9000);
  52.                     }
  53.                     Sleep(DMS_POLL_DELAY);
  54.                 }
  55.             }
  56.             ie->Stop();
  57.             IHTMLDocument2Ptr doc=NULL;
  58.             
  59.             try { 
  60.                 doc=ie->GetDocument();
  61.             } catch(...) {
  62.             }
  63.                 
  64.         
  65.             if(doc) {
  66.                 
  67.                 bstr_t html;
  68.                 LinkInfo *links=downloadInfo->links;
  69.                 for(int j=0, linksCount=downloadInfo->linksCount; j<linksCount; j++) { // skipping postdata
  70.                     LinkInfo l=links[j];
  71.                     html+="<a href=\""+l.url+"\">"
  72.                         +l.comment+"</a>";
  73.                 }
  74.                 IHTMLElementPtr body = doc->Getbody();
  75.                 if(body)
  76.                 {
  77.                     body->innerHTML=html;
  78.                 
  79.                     VARIANT v;
  80.                     v.vt=VT_DISPATCH ;
  81.                     v.pdispVal = doc;
  82.                     
  83.                     helper.invoke("LeechLinks",&v,1);
  84.                 }
  85.                 
  86.             }
  87.         }
  88.     }
  89. }